package io.renren.modules.weldingmachine.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import io.renren.modules.weldingmachine.entity.WarnInfoResponse;
import io.renren.modules.weldingmachine.service.impl.WeldingmachineServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.util.Optional;
import java.util.List;

@RestController
public class WarnInfoController {
    private final WeldingmachineServiceImpl weldingmachineService;

    @Autowired
    public WarnInfoController(WeldingmachineServiceImpl weldingmachineService) {
        this.weldingmachineService = weldingmachineService;
    }

    @GetMapping("/warninfo")
//    public ResponseEntity<List<WarnInfo>> getWarnInfo(
    public ResponseEntity<List<WarnInfoResponse.WarnInfo>> getWarnInfo(
            @RequestParam Optional<Long> warninfoId,
            @RequestParam Optional<String> warnCode,
            @RequestParam Optional<String> warnComment,
//            @RequestParam String warnTime,
            @RequestParam Optional<String> warnPa,
            @RequestParam Optional<String> warnPv,
            @RequestParam Optional<Integer> wmId,
            @RequestParam Optional<String> wmNo,
            @RequestParam Integer pageSize,
            @RequestParam Integer pageNum
            ) throws JsonProcessingException, UnsupportedEncodingException {
        List<WarnInfoResponse.WarnInfo> warnInfos = weldingmachineService.getWarnInfo(warninfoId, warnCode,warnComment,warnPa,warnPv,wmId,wmNo,pageSize,pageNum);
        return ResponseEntity.ok(warnInfos);
    }
}
